$(function() {
    $("#transactionTable").bootstrapTable('destroy').bootstrapTable({
        url : window.portAddress + "/transaction/transactionList",
        dataType : "json",
        method : 'get',
        striped: true,  //行间隔色
        cache : false,  //禁用缓存
        pageNumber: 1,  //初始化加载第一页
        pagination: true,//是否分页
        sidePagination: "client",//前端分页
        pageSize: 5,//单页记录数
        pageList: [5, 10, 15],//可选择单页记录数
        clickToSelect : true,
        theadClasses: "thead-pink",
        queryParams: function (params) {
            //向服务器传递的参数
            return {
               /* option : $("#search_option option:selected").val(),*/
                tradeDate : $("#tradeDate").val(),
                withdrawalCcy : $("#withdrawalCCy option:selected").val(),
                depositeCcy : $("#depositeCCy option:selected").val(),
                dealNo:  $("#dealNo").val(),
            };
        },
        responseHandler : function(res) {
            return res.data;
        },
        columns : [
            {
                title : "交易日期",
                field : "tradeDate",
                align : "center",
            },
            {
                title : "结算日期",
                field : "valueDate",
                align : "center",

            },
            {
                title : "货币对",
                field : "excde",
                align : "center",

            },
            {
                title : "买入货币(银行)",
                field : "withdrawalCcy",
                align : "center",
            },
            {
                title : "买入金额(银行)",
                field : "withdrawalAmt",
                align : "center",
            },
            {
                title : "卖出货币(银行)",
                field : "depositeCcy",
                align : "center",
            },
            {
                title : "卖出金额(银行)",
                field : "depositedAmt",
                align : "center",
            },
            {
                title : "对客汇率",
                field : "bankCostRate",
                align : "center",
            },
            {
                title : "交易编号",
                field : "dealNo",
                align : "center",
            }
        ]
    });

    $("#search").click(function() {

        $.ajax({
            url : window.portAddress + "/transaction/transactionList",
            type : "post",
            data : {
                tradeDate : $("#tradeDate").val(),
                withdrawalCcy : $("#withdrawalCCy option:selected").val(),
                depositeCcy : $("#depositeCCy option:selected").val(),
                dealNo:  $("#dealNo").val(),
            },
            dataType : "json",
            success : function(data) {
                if (data.state === '000000') {
                    toastr.success("查询数据成功");
                }else {
                    toastr.error(data.message);
                }
                $("#transactionTable").bootstrapTable("refresh");
            }
        })
    });


    $("#export").click(function() {

       var baseUrl = window.portAddress + "/transaction/export?";
       var tradeDate = $("#tradeDate").val();
       var  withdrawalCcy = $("#withdrawalCCy option:selected").val();
       var  depositeCcy = $("#depositeCCy option:selected").val();
       var  dealNo = $("#dealNo").val();


        window.location= baseUrl + "tradeDate=" + tradeDate + "&"
                                 + "withdrawalCcy=" + withdrawalCcy + "&"
                                 + "depositeCcy=" + depositeCcy + "&"
                                 + "dealNo=" + dealNo

    });


})
